<template>
    <div>
        <router-link tag='div' to='/' class="header-abs" v-show='showAbs'>
            <span class="iconfont header-abs-back">&#xe610;</span>
        </router-link>
        <div class="header-fixed" v-show='!showAbs' :style='opacityStyle'>
            景点详情
            <router-link to='/'>
                <span class="iconfont fixed-header-back">&#xe610;</span>
            </router-link>
        </div>
    </div>
</template>

<script>
export default {
    name: 'DetailHeader',
    data(){
        return {
            showAbs: true,
            opacityStyle: {
                opacity: 0
            }
        }
    },
    methods:{
        handleScroll(){
            var top = document.documentElement.scrollTop
            if(top > 10){
                let opacity = top / 198
                if(top > 140){
                    opacity = opacity > 1 ? 1: opacity
                }
                this.opacityStyle = { opacity }
                this.showAbs = false  
            }else{
                this.showAbs = true
            }
        }
    },
    activated (){
        window.addEventListener('scroll', this.handleScroll)
    },
    deactivated(){
        window.removeEventListener('scroll',this.handleScroll)
    }
}
</script>

<style lang="stylus" scoped>
    @import '~style/varibles.styl'
    .header-abs
        position: absolute
        top: .1rem
        left: .1rem
        height: .72rem
        line-height: .72rem
        width: .72rem
        text-align: center
        border-radius: 50%
        background: rgba(0,0,0,.5)
        .header-abs-back
            color: #fff
    .header-fixed
        z-index: 2
        position: fixed
        top: 0
        left: 0
        right: 0
        height: $headerHeight
        line-height: $headerHeight
        text-align: center
        color: #fff
        background: $bgColor
        font-size: .32rem
        .fixed-header-back
            position: absolute
            top: 0
            left: 0
            width: .64rem
            text-align: center
            color:#fff
</style>